home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0177_Delphi 2.0 Execute & Wait Routine.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-30  |  1.9 KB  |  59 lines

  1. unit WinExc32;
  2.  
  3. // This unit is based upon the well-known and largely used WinExecAndWait function
  4. // The former WinexecAndWait function doesn't compile under Delphi 2.0 because the
  5. // GetModuleUsage function is no longer supported under Win95.
  6. // I have simply updated the previous code so that it works with Delphi 2.0
  7. // under Windows 95. With this function you can call Windows-based applications
  8. // as well as Dos-based commands. That is 'c:\myapp\app32.exe' as well as
  9. // 'command.com /c del *.bak'.
  10. // This new WinexecAndWait32 is intended for Delphi 2.0 Win95 only,
  11. // it works for me but you use it at your own risk.
  12.  
  13. // Updated : July 31, 1996.
  14. // Author : Francis PARLANT CIS : 100113,3015.
  15.  
  16. interface
  17.  
  18. function WinExecAndWait32(Path: PChar; Visibility: Word): integer;
  19.  
  20. implementation
  21.  
  22. function WinExecAndWait32(Path: PChar; Visibility: Word): integer;
  23. var
  24.      Msg: TMsg;
  25.      lpExitCode : integer;
  26.      StartupInfo: TStartupInfo;
  27.      ProcessInfo: TProcessInformation;
  28. begin
  29.     FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  30.     with StartupInfo do
  31.     begin
  32.         cb := SizeOf(TStartupInfo);
  33.         dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  34.         wShowWindow := visibility; {you could pass sw_show or sw_hide as parameter}
  35.     end;
  36.     if CreateProcess(nil,path,nil, nil, False,
  37.         NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then begin
  38.         repeat
  39.             while PeekMessage(Msg, 0, 0, 0, pm_Remove) do
  40.                 begin
  41.                     if Msg.Message = wm_Quit then Halt(Msg.WParam);
  42.                     TranslateMessage(Msg);
  43.                     DispatchMessage(Msg);
  44.                 end;
  45.                 GetExitCodeProcess(ProcessInfo.hProcess,lpExitCode);
  46.         until lpExitCode<>Still_Active;
  47.         with ProcessInfo do {not sure this is necessary but seen in in some code elsewhere}
  48.         begin
  49.             CloseHandle(hThread);
  50.             CloseHandle(hProcess);
  51.         end;
  52.         result := 0; {sucess}
  53.     end
  54.     else
  55.         result:=GetLastError;{error occurs during CreateProcess see help for details}
  56. end;
  57.  
  58. end.
  59.